package com.fortune.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fortune.common.paging.PagingData;
import com.fortune.dao.MDataAnalysisDao;
import com.fortune.dto.in.mDataAnalysis.MProductStoreDetailListDto;
import com.fortune.dto.in.mDataAnalysis.OrderCollectionDto;
import com.fortune.entity.MProductStockDetailInfo;
import com.fortune.entity.MUserInfo;
import com.fortune.service.MDataAnalysisService;
import com.fortune.vo.mDataAnalysis.Dearler;
import com.fortune.vo.mDataAnalysis.MProduct;
import com.fortune.vo.mDataAnalysis.OrderCollection;
@Service
public class MDataAnalysisServiceImpl implements MDataAnalysisService {
	@Autowired
	private MDataAnalysisDao mDataAnalysisDao;
	@Override
	public PagingData<MProductStockDetailInfo> mProductStoreDetailList(MUserInfo mUserInfo, MProductStoreDetailListDto listDto) {
		List<MProductStockDetailInfo> list = mDataAnalysisDao.list(mUserInfo, listDto);
		int count = mDataAnalysisDao.count(mUserInfo, listDto);
		PagingData<MProductStockDetailInfo> pagingData = new PagingData<>(list, count);
		return pagingData;
	}
	@Override
	public PagingData<OrderCollection> orderCollection(MUserInfo mUserInfo,OrderCollectionDto orderCollectionDto) {
		List<MProduct> pName = mDataAnalysisDao.pName(mUserInfo);
		Map<String,Object> map = new HashMap<>();
		map.put("dealer", "经销商");
		for (MProduct mProduct : pName) {
			map.put(mProduct.getId().toString(), mProduct.getName());
		}
		List<Map<String,Object>> list = new ArrayList<>();
		list.add(map);
		List<Dearler> dids = mDataAnalysisDao.dealers(mUserInfo, orderCollectionDto);
		for(Dearler dearler:dids){
			Map<String, Object> countMap = new HashMap<>();
			countMap.put("dealer", dearler.getName());
			for (MProduct mProduct: pName) {
				int count = mDataAnalysisDao.orderCount(mUserInfo, orderCollectionDto, dearler.getDid(),mProduct.getId());
				countMap.put(mProduct.getId().toString(), count);
			}
			list.add(countMap);
		}
		System.out.println(list);
		return null;
	}

}
